# import json
#
# import aio_pika
# import pika
# from starlette.websockets import WebSocket
#
# from config import RABBITMQ_URL, RABBITMQ_QUEUE
#
# connection = pika.BlockingConnection(
#         pika.ConnectionParameters("192.168.10.126", 5672, '/',heartbeat=0)
#     )
# channel = connection.channel()
#
# def pub_gen(task_id, msg, docid, taskdocid):
#     try:
#         channel.basic_publish(
#             exchange='',
#             routing_key=RABBITMQ_QUEUE,
#             body=json.dumps({"text":msg,"task_id":task_id, "docId":docid, "taskDocId":taskdocid},ensure_ascii=False)
#         )
#     except Exception as e:
#         ex = str(e)
#         print(f"消息队列异常{ex}")
#
# if __name__ == "__main__":
#     pass
import json
from src.huey_init.storages import r

def pub_gen(task_id, msg, docid, taskdocid):
    try:
        json_body = json.dumps({"text":msg,"task_id":task_id, "docId":docid, "taskDocId":taskdocid},ensure_ascii=False)
        r.publish("channel:1", json_body)
    except Exception as e:
        ex = str(e)
        print(f"消息队列异常{ex}")

if __name__ == "__main__":
    pub_gen("111", "测试用", "xxxxxxxxxxxxxxxxx-sssssssss", "dsafsads-sssssssssssssssxxxxx")
